package com.sdy.dataexchange.meta.util;

import com.sdy.dataadapter.DataAdapter;
import com.sdy.dataadapter.DbType;
import com.sdy.dataadapter.RawDataSource;
import com.sdy.dataexchange.biz.model.ExDbDict;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author: 王越洋
 * @version: v1.0
 * @description: com.sdy.dataexchange.meta.util
 * @date:2019/10/23
 */
@Slf4j
@Component
public class JdbcUtil {
    public DataAdapter getDataAdapter(ExDbDict exDbDict) {
        DataAdapter dataAdapter = null;
        if (!exDbDict.getDbType().isEmpty()) {
            if (exDbDict.getDbType().equals("ORACLE")) {
                dataAdapter =
                        new DataAdapter(
                                new RawDataSource(DbType.ORACLE,
                                        exDbDict.getDbIp(),
                                        exDbDict.getDbPort(),
                                        exDbDict.getDbName(),
                                        exDbDict.getDbUser(),
                                        exDbDict.getDbPasswd(),
                                        null));
            } else if (exDbDict.getDbType().equals("MYSQL")) {
                dataAdapter =
                        new DataAdapter(
                                new RawDataSource(DbType.MYSQL,
                                        exDbDict.getDbIp(),
                                        exDbDict.getDbPort(),
                                        exDbDict.getDbName(),
                                        exDbDict.getDbUser(),
                                        exDbDict.getDbPasswd(),
                                        null));
            } else {
                log.info("数据库类型有误 暂不支持");
            }
        }
        return dataAdapter;
    }
}
